import os

if __name__ == '__main__':

    while True:

        pat = str(input('请输入文件夹地址(输入q退出)：'  ''))

        if os.path.isdir(pat):
            class DirSize:
                tlt_size = 0

                def __init__(self, path):
                    if os.path.isdir(path):
                        for f in os.listdir(path):
                            _ = DirSize(path + '\\' + f)
                    else:
                        DirSize.tlt_size += os.path.getsize(path)


            c = DirSize(pat)
            print('该文件夹大小为：' + str(c.tlt_size))

        else:
            if pat == 'q':
                break
            else:
                print('该目录不是文件夹，请核实')
